package org.springblade.third.provider;

import org.springblade.third.dto.ThirdRequest;
import org.springblade.third.dto.ThirdResponse;
import org.springblade.third.spi.ChannelProvider;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class RandomFailProvider implements ChannelProvider {
    private final Random random = new Random();

    @Override
    public boolean supports(String channelCode, String productCode) {
        return "TEST".equalsIgnoreCase(channelCode) && "RANDOM".equalsIgnoreCase(productCode);
    }

    @Override
    public ThirdResponse<Object> execute(ThirdRequest request) {
        if (random.nextBoolean()) {
            throw new RuntimeException("Random failure");
        }
        return ThirdResponse.ok("OK");
    }
}



